<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>添加用户信息</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<meta name="apple-mobile-web-app-status-bar-style" content="black">
	<meta name="apple-mobile-web-app-capable" content="yes">
	<meta name="format-detection" content="telephone=no">
	<link rel="stylesheet" href="/assets/layui-v2.5.5/css/layui.css" media="all" />
	<link type="text/css" rel="stylesheet" href="/assets/tree/metroStyle.css">
</head>
<body>
<div class="layui-fluid" style="margin-top:2%;">
		<form class="layui-form">
			 	  <div class="layui-form-item">
				    <label class="layui-form-label">账号<font color="#FF0000">*</font></label>
				    <div class="layui-input-block">
				      <input type="text" name="loginName" lay-verify="required" autocomplete="off" placeholder="请输入账号" class="layui-input">
				    </div>
				  </div>
				  <div class="layui-form-item">
				    <label class="layui-form-label">用户名<font color="#FF0000">*</font></label>
				    <div class="layui-input-block">
				      <input type="text" name="userName" lay-verify="required"  autocomplete="off" placeholder="请输入姓名"class="layui-input">
				    </div>
				  </div>
				  <div class="layui-form-item">
				    <label class="layui-form-label">密码<font color="#FF0000">*</font></label>
				    <div class="layui-input-block">
				      <input type="password" name="password" lay-verify="required" autocomplete="off" placeholder="请输入密码" class="layui-input">
				    </div>
				  </div>
				  <div class="layui-form-item">
				    <label class="layui-form-label">重复密码<font color="#FF0000">*</font></label>
				    <div class="layui-input-block">
				      <input type="password" name="repassword"  lay-verify="required" autocomplete="off" placeholder="请重复密码" class="layui-input">
				    </div>
				  </div>				  			   
			   <div class="layui-form-item">
				    <label class="layui-form-label">区划(单位)(单选)<font color="#FF0000">*</font></label>
				    <div class="layui-input-block">
				      <textarea  lay-verify="required" class="layui-textarea"  type="text" id="mytextarea1" readonly></textarea>
				    </div>
			  </div>
			  <div class="layui-form-item">
				    <label class="layui-form-label">角色<font color="#FF0000">*</font></label>
				     <div class="layui-input-block">
				     #for(x:roles)
				     	<input type="checkbox" lay-skin="primary" title=#(x.roleName) value=#(x.id)>
				     #end
				    </div>
			  </div>
			  <div class="layui-form-item">
				  <div class="layui-input-block" style="text-align: center;margin:0 auto;">
					  <button class="layui-btn" lay-submit="" lay-filter="submit-user">保存</button>
					  <button type="reset" class="layui-btn layui-btn-primary">重置</button>
				  </div>
			  </div>
		</form>
	</div>
<script src="/assets/js/jquery-1.4.4.min.js"></script>
<script type="text/javascript" src="/assets/tree/jquery.ztree.all.js"></script>
<script type="text/javascript" src="/assets/tree/MultipleTreeSelect.js"></script>
<script src="/assets/layui-v2.5.5/layui.js" charset="utf-8"></script> 
<script>
var form,result;
	layui.use(['form','laydate'], function(){
	    form = layui.form;
	    form.render();
	    zNodes=#(areas);
        defaults = {
            zNodes: zNodes,
            height:333
        }
		$("#mytextarea1").drawMultipleTree(defaults);
        //重置按钮重置角色和单位
        $(".layui-btn-primary").click(function(){
        	$("#mytextarea1").text("");       	
        });
		//提交表单
		form.on('submit(submit-user)', function(obj){
			result = [];
			$('input[type="checkbox"]:checked').each(function() {
			    result.push($(this).val());
			});
			saveUser(obj.field);
			return false;
		});
	});
function saveUser(params){
	params.areaId=aaa;
	params.roleIds=result.join(',');
 	$.ajax({
	    url : '/user/userSave',
		type : "post",
		data : params,
		dataType : "json",
		success : function(ret) {
			if (ret.state == 'ok') {
				layer.msg(ret.msg, {icon: 1, offset: '15px', time: 600}, function(){
					var index = parent.layer.getFrameIndex(window.name);
					parent.layer.close(index);
					parent.$(".layui-laypage-btn").click();
				});
			} else {
				layer.msg(ret.msg, {icon: 2, offset: '10px'});
			}
		},
		error: function() {
      } 
  }); 
}
</script> 
</body>
</html>